import _axios from "@/ajax/axios.js";
const ajax = (
    url,
    data = {},
    type = "GET"
) => {
    if (type == "GET") {
        const keys = Object.keys(data);
        let dataStr = `/${url}`;
        if (keys.length > 0) {
            dataStr += `?`;
            keys.forEach((key) => {
                dataStr += `${key}=${data[key]}&`;
            });
            dataStr = dataStr.substr(0, dataStr.lastIndexOf("&"));
            console.log(dataStr, 1);
        }
        return _axios.get(dataStr);
    } else if (type == 'POST') {
        return _axios.post(url, JSON.stringify(data));
    }
};


export default ajax